//
//  YYEStatus.swift
//  weibo14
//
//  Created by mac on 16/3/7.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class YYEStatus: NSObject {

   
    // 如果定义成 Int,在32位的系统架构上为Int32,其最大值是没有微博的id大的,是装不下
    var id: Int64 = 0

    // 微博的内容
    var text: String?
    // 当前微博的创建时间  这里最先拿到时间的字符串
    var created_at: String?{
        didSet{
        
            created_date = NSDate.string2Date(created_at)
        }
    }
    
    var created_date: NSDate?
    
    // 微博来源
    var source: String?
    
    
    // 当前发送此条微博的用户信息
    var user: YYEUser?
    // 转发数量
    var reposts_count: Int = 0
    // 评论数量
    var comments_count: Int = 0
    // 点赞数量
    var attitudes_count: Int = 0
    // 转发微博--------------------类似回调自己
    var retweeted_status: YYEStatus?
    
    // 图片信息-----------key值
    var pic_urls: [YYEStatusPictureInfo]?
    

    init(dict:[String:AnyObject]) {
        super.init()

        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String){}
    
   // 因为user是一个类 要特殊处理
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            guard let v = value as? [String: AnyObject] else {
                return
            }
            user = YYEUser(dict: v)
        }else if key == "retweeted_status" {
            guard let v = value as? [String: AnyObject] else {
                return
            }
            retweeted_status = YYEStatus(dict: v)
        }else if key == "pic_urls" {
            guard let arr = value as? [[String: AnyObject]] else {
                return
            }
            
            
            var  temp = [YYEStatusPictureInfo]()
            for vale in  arr {
            
                let model = YYEStatusPictureInfo(dict: vale)
            
                temp.append(model)
            }
            
            pic_urls = temp
            
            
        } else{
            super.setValue(value, forKey: key)
        }
        
    }
    
    
}
